package com.lagou.module2.task1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class TestDB {


    public static void main(String[] args) throws SQLException {

        //1、获取数据库连接
        Connection con = DBUtils.getConnection();

        //2.获取预处理对象
        String sql = "select * from employee where name = ? and gender = ?";
        PreparedStatement ps = con.prepareStatement(sql);

        //3.设置占位符的值
        ps.setString(1, "貂蝉");
        ps.setString(2, "女");

        //4、获取结果集
        ResultSet resultSet = ps.executeQuery();

        //4.处理结果集
        while(resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String gender = resultSet.getString("gender");
            double salary = resultSet.getDouble("salary");
            double bonus = resultSet.getDouble("bonus");
            Date date = resultSet.getDate("join_date");
            System.out.println(id +" " + name + " " + gender +" " + salary +" " + bonus +" " +date);
        }

        //5.释放资源
        DBUtils.close(con,ps,resultSet);

    }
}
